﻿label start:
    
    # キャラクターを記述します
    $ pc = Character('れんぱいﾀﾝ', color="#c8ffc8")
    define nvln = NVLCharacter(None, window_style="centered_window")
    # ゲーム内で使う画像に名前をつけます。
    image bg room = "picture/DummyBg001.jpg"  #メインの部屋
    $ renpy.copy_images('youjo','pc')
    
    # カレンダー日めくり表示のアニメーション
    image calendar:
            Text("%d年目  %d月"% (year, month-1), color="#fff", size=72) with dissolve
            time 1.0
            Text("%d年目  %d月"% (year,month), color="#fff", size=72) with dissolve
        
    scene black
    nvl show dissolve
    nvln "人間と魔物の間に休戦協定が結ばれ、\n\
          ある意味、平和になった魔界。\n\
          しかし、魔物は平和と言う名の退屈に飽きていた\n\
          魔界のあちこちでくだらない争いが頻発するようになり、\n\
          それに頭を悩ませた大魔王 ( 仮 ) は人間界にある闘技場に目をつけ、\n\
          「争うなら場所を与えてやろう!褒美は・・・・。」\n\
          褒美の内容を聞いて魔物はつまらに争いをせずに、\n\
          その場所に集うようになりました。\n\
          その褒美とは・・・・"
    nvl hide dissolve

# 一日の始まり
label startDay:
    scene black
    with dissolve
    
    if monthweek != 1:
        if restcount <= 0:
            "[year]年目[month]月[monthweek]週"
    elif year != 1 or month != 4:
        show calendar at Position(xalign=.5, yalign=.5)with dissolve
        $ renpy.pause(3.0)
        hide  calendar
        if furniture_house is None:
            if money >= 1000:
                "家賃を1000G払いました。"
                $money -= 1000
            else:
                "お金が足りなくて家賃が払えませんでした"
                jump gameover
            
    if restcount <= 0:
        scene bg room
        with dissolve
    show expression Text("   [year]年目\n[month]月 [monthweek]週", size=50, yalign=0.05, xalign=0.95, drop_shadow=(2, 2)) as text
    
    if week == 47:
        jump pre_metamorphosis
    elif week == 0 and year != 1:
        call post_metamorphosis
    
    $ condition()
    if hp <= 0 and restcount <= 0:
        "とっても疲れているみたい\nしばらく休養を取ろう"
        $ restcount = 4
    if stress >= 100 and restcount <= 0:
        "とってもイライラしているみたい\nしばらく休養を取ろう"
        $ restcount = 4
    if restcount>0:
        $ restcount -= 1
        if restcount <= 0:
            $ hp = max_hp
            $ stress = 0
        jump endDay
    if monthweek == 1:
        if stress > 50:
            "ストレスが溜まっている"
        elif modified_max_hp / 2 > hp:
            "疲れている"
        elif modified_max_hp == hp and stress == 0:
            "元気のようだ"
        else:
            "普通のようだ"
    "今日は何をしようか"
    

# メインメニュー
label mainMenu:
    python:
        category = None
        while True:
            condition()
            ui.frame(xpos=0,
                     ypos=200,
                     xanchor='left',
                     yanchor='top',
                     xfill=False,
                     xminimum=300
                     )
            ui.vbox()
            ui.textbutton("アルバイト", clicked=ui.returns(("info", "labor", None)))
            ui.textbutton("教育", clicked=ui.returns(("info", "training", None)))
            ui.textbutton("おでかけ", clicked=ui.returns(("info", "shopping", None)))
            ui.textbutton("家具屋", clicked=ui.returns(("furniture", None, None)))
            ui.textbutton("休憩", clicked=ui.returns(("holiday", None, None)))
            ui.textbutton("ステータス", clicked=ui.returns(("chart", None, None)))
            if config.developer:
                ui.textbutton("年度末に飛ぶ", clicked=ui.returns(("year_end", None, None)))
            ui.close()
            if category is not None and action != "holiday":
                ui.frame(xpos=300,
                         ypos=200,
                         xanchor='left',
                         yanchor='top',
                         xfill=False,
                         xminimum=500,
                         xmargin = 10
                         )
                ui.vbox()
                if category == "labor":
                    for (i, row) in enumerate(arbeitlist):
                        ui.textbutton(row[arbeitheader.index("アルバイト項目")], clicked=ui.returns(("decide_arbeit", row[arbeitheader.index("アルバイトNo")], i)), hovered=ui.returns(("info", row[arbeitheader.index("アルバイトNo")], i)))
                elif category == "training":
                    for (i, row) in enumerate(lessonlist):
                        ui.textbutton(row[lessonheader.index("教育項目")], clicked=ui.returns(("decide_lesson", row[lessonheader.index("教育No")], i)), hovered=ui.returns(("info", row[lessonheader.index("教育No")], i)))
                elif category == "shopping":
                    ui.textbutton("武器屋", clicked=ui.returns(("weapon", None, None)))
                    ui.textbutton("防具屋", clicked=ui.returns(("armor", None, None)))
                    ui.textbutton("バカンス", clicked=ui.returns(("vacation", None, None)))
                ui.close()
            ui.frame(xpos=800,
                     ypos=200,
                     xanchor='left',
                     yanchor='top',
                     xfill=False,
                     xminimum=300
                     )
            ui.vbox()
            ui.text("%d/%d" % (hp, modified_max_hp))
            ui.bar(modified_max_hp, hp, xmaximum = 100)
            if config.developer:
                ui.text("ストレス %d%%" % (stress), minwidth=120)
                ui.bar(100, stress, xmaximum = 100)
            ui.text("所持金:%dG" % money)
            ui.close()
            action, category, number = ui.interact()
            if action in ("decide_arbeit", "decide_lesson"):
                if confirm("本当によろしいですか?") == True:
                    break
            elif action == "chart":
                renpy.jump("chart")
            elif action == "weapon":
                renpy.jump("weaponShop")
            elif action == "armor":
                renpy.jump("armorShop")
            elif action == "furniture":
                renpy.jump("furniture_shop")
            elif action == "holiday":
                if confirm("本当によろしいですか?") == True:
                    renpy.jump("holiday")
            elif action == "vacation":
                if confirm("本当によろしいですか?", enabled = money >= 2500):
                    renpy.jump("vacation")
            elif action == "year_end":
                week = 43
                renpy.jump("endDay")
            for row in arbeitlist:
                if category == row[arbeitheader.index("アルバイトNo")]:
                    narrator(row[arbeitheader.index("info")], interact=False)
                    category = "labor"
            for row in lessonlist:
                if category == row[lessonheader.index("教育No")]:
                    narrator(row[lessonheader.index("info")], interact=False)
                    category = "training"

    $dissolve = Dissolve(2.0)
    scene black
    with dissolve
    python:
        if action == "decide_arbeit": 
            decideheader = arbeitheader
            decidelist = arbeitlist
        if action == "decide_lesson": 
            decideheader = lessonheader
            decidelist = lessonlist
        hp = hp - round(modified_max_hp * float(decidelist[number][2]))
        if random.randint(0,200) <= (hp / max_hp + (100-stress) /100)*100 :
            growth = 1
            ui.text("成功")
            renpy.show('pc smile')
            ###ここに"成功"のポップアップ処理を入れる###
        else:
            growth = 2
            ui.text("失敗")
            renpy.show('pc sad')
            ###ここに"失敗"のポップアップ処理を入れる###
        renpy.call_in_new_context(category)
        
        txt = ""
        for i in range(3, 14, 2):
            updown = 0
            if int(decidelist[number][i]) | int(decidelist[number][i]) != 0:
                updown = int(random.randrange(int(decidelist[number][i]), int(decidelist[number][i+1])) / growth)
            if updown > 0:
                txt += decideheader[i] + "が " + str(updown) + " 上がった！\n"
            elif updown < 0:
                txt += decideheader[i] + "が " + str(abs(updown)) + " 下がった！\n"
            if decideheader[i] == "HP": change_status(max_hp = updown)
            if decideheader[i] == "体力": change_status(stamina = updown)
            if decideheader[i] == "力": change_status(power = updown)
            if decideheader[i] == "かしこさ": change_status(intelligence = updown)
            if decideheader[i] == "容姿": change_status(pretty = updown)
            if decideheader[i] == "センス": change_status(sense = updown)
        stress = min(max(stress + int(decidelist[number][decideheader.index("ストレス")]), 0),100)
        txt += "ストレスが " + decidelist[number][decideheader.index("ストレス")] + " たまった\n"
        money = min(max(money + int(decidelist[number][decideheader.index("お金")]), 0),999999)
        if action == "decide_arbeit": txt += "給料を " + decidelist[number][decideheader.index("お金")] + " G もらった！\n"
        if action == "decide_lesson": txt += "お金を " + str(abs(int(decidelist[number][decideheader.index("お金")]))) + " G 使った！\n"
    "[txt]"
    jump endDay

    label endDay:
        $dissolve = Dissolve(0.5)
        
        #一日進める
        python:
            week += 1
            if week >= 48:
                week = 0
                year += 1
            month = (week / 4 + 3) % 12 + 1
            monthweek = week%4+1
        jump startDay

# 武器屋
label weaponShop:
    hide pc
    python:
        point_list = ["HP", "体力", "力", "賢さ", "容姿", "センス"]
        while True:
            ui.frame(xpos=0,
                     ypos=200,
                     xanchor='left',
                     yanchor='top',
                     xfill=False,
                     xminimum=300
                     )
            ui.vbox()
            for index, weapon in enumerate(weaponList):
                ui.textbutton("%s %dG" % (weapon[0], weapon[7]), clicked = None if not (equipWeapon is None or equipWeapon < index) or money < weapon[7] else ui.returns(("buy", index)), hovered=ui.returns(("info", index)))
            ui.textbutton("戻る", clicked = ui.returns(("back", None)))
            ui.close()
            behavior, index = ui.interact()
            if behavior == "info":
                narrator("\n".join(["%s+%d" % (point_list[i], point) for i, point in enumerate(weaponList[index][1:7]) if point != 0]), interact = False)
            elif behavior == "buy":
                if confirm("%sを購入します" % (weaponList[index][0])):
                    money -= weaponList[index][7]
                    equipWeapon = index
                    change_equip("weapon", **{"max_hp": weaponList[index][1], "stamina": weaponList[index][2], "power": weaponList[index][3], "intelligence": weaponList[index][4], "pretty": weaponList[index][5], "sense": weaponList[index][6]})
                    renpy.jump("mainMenu")
            elif behavior == "back":
                renpy.jump("mainMenu")

# 防具屋
label armorShop:
    hide pc
    python:
        point_list = ["HP", "体力", "力", "賢さ", "容姿", "センス"]
        while True:
            ui.frame(xpos=0,
                     ypos=200,
                     xanchor='left',
                     yanchor='top',
                     xfill=False,
                     xminimum=300
                     )
            ui.vbox()
            for index, armor in enumerate(armorList):
                ui.textbutton("%s %dG" % (armor[0], armor[7]), clicked = None if not (equipArmor is None or equipArmor < index) or money < armor[7] else ui.returns(("buy", index)), hovered=ui.returns(("info", index)))
            ui.textbutton("戻る", clicked = ui.returns(("back", None)))
            ui.close()
            behavior, index = ui.interact()
            if behavior == "info":
                narrator("\n".join(["%s+%d" % (point_list[i], point) for i, point in enumerate(armorList[index][1:7]) if point != 0]), interact = False)
            elif behavior == "buy":
                if confirm("%sを購入します" % (armorList[index][0])):
                    money -= armorList[index][7]
                    equipArmor = index
                    change_equip("armor", **{"max_hp": armorList[index][1], "stamina": armorList[index][2], "power": armorList[index][3], "intelligence": armorList[index][4], "pretty": armorList[index][5], "sense": armorList[index][6]})
                    renpy.jump("mainMenu")
            elif behavior == "back":
                renpy.jump("mainMenu")

# 家具屋
label furniture_shop:
    hide pc
    python:
        bed_list = [{'name': '粗末なベッド', 'hp': 3, 'price': 2500},
                    {'name': '普通のベッド', 'hp': 5, 'price': 5000},
                    {'name': '豪華なベッド', 'hp': 10, 'price': 10000}]
        tv_list = [{'name': 'ブラウン管テレビ', 'stress': 3, 'price': 2500},
                   {'name': '液晶テレビ', 'stress': 5, 'price': 5000},
                   {'name': 'プラズマテレビ', 'stress': 10, 'price': 10000}]
        house_list = [{'name': 'あばら家', 'stress': -10, 'price': 3000},
                      {'name': '普通の家', 'stress': -5, 'price': 7500},
                      {'name': '豪邸', 'stress': 5, 'price': 25000}]
        while True:
            ui.frame(xpos=0,
                     ypos=200,
                     xanchor='left',
                     yanchor='top',
                     xfill=False,
                     xminimum=300
                     )
            ui.vbox()
            for index, bed in enumerate(bed_list):
                ui.textbutton("%s %dG" % (bed['name'], bed['price']), clicked = None if not (furniture_bed is None or furniture_bed < index) or money < bed['price'] else ui.returns(("bed", "buy", index)), hovered=ui.returns(("bed", "info", index)))
            for index, tv in enumerate(tv_list):
                ui.textbutton("%s %dG" % (tv['name'], tv['price']), clicked = None if not (furniture_tv is None or furniture_tv < index) or money < tv['price'] else ui.returns(("tv", "buy", index)), hovered = ui.returns(("tv", "info", index)))
            for index, house in enumerate(house_list):
                ui.textbutton("%s %dG" % (house['name'], house['price']), clicked = None if not (furniture_house is None or furniture_house < index) or money < house['price'] else ui.returns(("house", "buy", index)), hovered = ui.returns(("house", "info", index)))
            ui.textbutton("戻る", clicked = ui.returns((None, "back", None)))
            ui.close()
            category, behavior, index = ui.interact()
            if behavior == "info":
                if category == "bed":
                    narrator("休憩時HP回復量+%d%%" % (bed_list[index]['hp']), interact = False)
                elif category == "tv":
                    narrator("行動時ストレス%d%%軽減" % (tv_list[index]['stress']), interact = False)
                elif category == "house":
                    narrator("行動時ストレス%d%%軽減\n家賃がなくなる" % (house_list[index]['stress']), interact = False)
            elif behavior == "buy":
                if category == "bed" and confirm("%sを購入します" % (bed_list[index]['name'])):
                    money -= bed_list[index]['price']
                    furniture_bed = index
                    renpy.jump("mainMenu")
                elif category == "tv" and confirm("%sを購入します" % (tv_list[index]['name'])):
                    money -= tv_list[index]['price']
                    furniture_tv = index
                    renpy.jump("mainMenu")
                elif category == "house" and confirm("%sを購入します" % (house_list[index]['name'])):
                    money -= house_list[index]['price']
                    furniture_house = index
                    renpy.jump("mainMenu")
            elif behavior == "back":
                renpy.jump("mainMenu")

# バカンス
label vacation:
    scene black with dissolve
    "バカンスをした。HPとストレス全回復。"
    python:
        hp = modified_max_hp
        stress = 0
        money -= 2500
        if not random.randrange(10):
            if random.choice((True, False)):
                random_weapon = random.randrange(9)
                if equipWeapon is None or equipWeapon < random_weapon:
                    equipWeapon = random_weapon
                    narrator("%sを拾った。" % weaponList[random_weapon][0])
            else:
                random_armor = random.randrange(9)
                if equipArmor is None or equipArmor < armorList[random_armor][0]:
                    equipArmor = random_armor
                    narrator("%sを拾った。" % random_armor)
    jump endDay

# 休憩
label holiday:
    python:
        hp_rate = 50 + (0 if furniture_bed is None else bed_list[furniture_bed]['hp'])
        hp_refresh = min(modified_max_hp - hp, modified_max_hp * hp_rate / 100)
        stress_refresh = min(stress, 50)
        hp += hp_refresh
        stress -= stress_refresh
    pc "たっぷり休憩したよ"
    "HPが [hp_refresh] ポイント回復しました。\nストレスが[stress_refresh]\%減った"
    jump endDay

# ステータス画面
label chart:
    hide pc
    python:
        statusList = [["体力", modified_stamina],
                      ["力", modified_power],
                      ["賢さ", modified_intelligence],
                      ["容姿", modified_pretty],
                      ["センス", modified_sense]
                      ]
        typeList = {"normal": "無"}
        while True:
            ui.frame(xpos=0,
                     ypos=200,
                     xanchor='left',
                     yanchor='top',
                     xfill=False,
                     xminimum=300
                     )
            ui.vbox()
            ui.hbox()
            ui.image(ImageReference('pc normal'))
            ui.vbox()
            ui.hbox()
            ui.text("HP %d/%d" % (hp, modified_max_hp), minwidth=120)
            ui.bar(modified_max_hp, hp, xmaximum = 100)
            ui.close()
            for status in statusList:
                ui.hbox()
                ui.text("%s %d" % (status[0], status[1]), minwidth=120)
                ui.bar(9999, status[1], xmaximum = 100)
                ui.close()
            if config.developer:
                ui.hbox()
                ui.text("ストレス %d%%" % (stress), minwidth=120)
                ui.bar(100, stress, xmaximum = 100)
                ui.close()
            ui.text("武器:%s" % ("なし" if equipWeapon is None else weaponList[equipWeapon][0]))
            ui.text("防具:%s" % ("なし" if equipArmor is None else armorList[equipArmor][0]))
            ui.text("所持金:%dG" % (money))
            ui.text(typeList[type] + "属性")
            ui.close()
            ui.close()
            ui.textbutton("戻る", clicked=ui.returns(True))
            ui.close()
            if ui.interact():
                renpy.jump("mainMenu")

# 変態前
label pre_metamorphosis:
    show pc normal
    "適当な文章も考えるのも面倒だ"
    jump endDay

# 変態後
label post_metamorphosis:
    image fire normal = "picture/girl_1.jpg"
    $ renpy.copy_images('fire', 'pc')
    show pc normal
    "適当な文章も考えるのも面倒だ"
    return

label gameover:
    show pc sad
    "ゲームオーバーです"
